capture log close
log using "${path_log}/06_analysis_bop_f.log", replace
 
use "${path_data}\bopf_final.dta", clear

*** Table 3: upper panel
eststo: qui did_imputation price_current BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) 
eststo: qui did_imputation price_current BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key sector_wave)
eststo: qui did_imputation price_current BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key sector_wave) timecontrols(energymix_*)
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key sector_wave)
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key sector_wave) timecontrols(energymix_*)

esttab using "${path_export_tables}\table_3_upper.tex", keep(tau) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("\midrule") nomtitles nonumbers fragment noobs varwidth(40) varlabel(tau "treated x post price increase") replace
	
est clear

*** Table 3: lower panel 	
eststo: qui did_imputation price_current BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) horizons(0(3)3)
add_info price_current, num(1) id(BBk_Sample_Key)
passthrough, num(1)  
eststo: qui did_imputation price_current BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key sector_wave) horizons(0(3)3)
add_info price_current, num(2) id(BBk_Sample_Key)
passthrough, num(2) 
eststo: qui did_imputation price_current BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key sector_wave) timecontrols(energymix_*) horizons(0(3)3)
add_info price_current, num(3) id(BBk_Sample_Key)
passthrough, num(3) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) horizons(0(3)3)
add_info inflexpoint, num(4) id(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key sector_wave) horizons(0(3)3)
add_info inflexpoint, num(5) id(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key sector_wave) timecontrols(energymix_*) horizons(0(3)3)
add_info inflexpoint, num(6) id(BBk_Sample_Key) 
 
esttab using "${path_export_tables}\table_3_lower.tex", keep(tau0 tau3) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("\midrule" "firm FE & {yes} & {yes} & {yes} & {yes} & {yes} & {yes} \\" "month FE & {yes} & & & {yes} & & \\" "sector x month FE &  & {yes} & {yes} &  & {yes} & {yes} \\" "energy share x month FE & &  & {yes} & & & {yes} \\" "\midrule" "energy price pass-through & ${passthrough1_str} & ${passthrough2_str} & ${passthrough3_str} & & & \\" " & ${passthrough1_se_str} & ${passthrough2_se_str} & ${passthrough3_se_str} & & & \\" "\midrule" "mean & ${mean1} &${mean2} & ${mean3}  & ${mean4} &${mean5} & ${mean6}\\" "N & ${N1} &${N2} & ${N3} & ${N4} &${N5} & ${N6} \\" "\# cluster & ${cluster1} &${cluster2} & ${cluster3} & ${cluster4} & ${cluster5} & ${cluster6} \\" "\bottomrule\bottomrule") nomtitles nonumbers fragment noobs varwidth(40) varlabel(tau0 "treated x quarter 0 after price increase" tau3 "treated x quarter 1 after price increase") replace

est clear

*** Figure 6 & Appendix Table B.12
mat estsave = J(5,4,.)
mat colname estsave =  "estmean" "estse" "estmean_int" "estse_int"

eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) wtr(d_no_monitor_energy d_monitor_energy) fe(BBk_Sample_Key d_monitor_energy_wave) maxit(999) 
mat estsave[5,1] = e(b)[1,1]
mat estsave[5,2] = sqrt(e(V)[1,1])
mat estsave[5,3] = e(b)[1,2]
mat estsave[5,4] = sqrt(e(V)[2,2])
pvalue, num(1)
add_info inflexpoint, num(1) id(BBk_Sample_Key)
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) wtr(d_smallfirm d_largefirm) fe(BBk_Sample_Key d_smallfirm_wave) maxit(999) 
mat estsave[4,1] = e(b)[1,1]
mat estsave[4,2] = sqrt(e(V)[1,1])
mat estsave[4,3] = e(b)[1,2]
mat estsave[4,4] = sqrt(e(V)[2,2])
pvalue, num(2)
add_info inflexpoint, num(2) id(BBk_Sample_Key)
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) wtr(d_low_energy d_high_energy) fe(BBk_Sample_Key d_low_energy_wave) maxit(999) 
mat estsave[3,1] = e(b)[1,1]
mat estsave[3,2] = sqrt(e(V)[1,1])
mat estsave[3,3] = e(b)[1,2]
mat estsave[3,4] = sqrt(e(V)[2,2])
pvalue, num(3)
add_info inflexpoint, num(3) id(BBk_Sample_Key)
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) wtr(d_non_firm_gas d_firm_gas) fe(BBk_Sample_Key d_firm_gas_wave) maxit(999) 
mat estsave[2,1] = e(b)[1,1]
mat estsave[2,2] = sqrt(e(V)[1,1])
mat estsave[2,3] = e(b)[1,2]
mat estsave[2,4] = sqrt(e(V)[2,2])
pvalue, num(4)
add_info inflexpoint, num(4) id(BBk_Sample_Key)
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) wtr(d_sector_nonint d_sector_intensive) fe(BBk_Sample_Key d_sector_int_wave) maxit(999) 
mat estsave[1,1] = e(b)[1,1]
mat estsave[1,2] = sqrt(e(V)[1,1])
mat estsave[1,3] = e(b)[1,2]
mat estsave[1,4] = sqrt(e(V)[2,2])
pvalue, num(5)
add_info inflexpoint, num(5) id(BBk_Sample_Key)

svmat estsave, names(col)

g time1 = _n + 0.1 if _n <= 5
g time2 = _n - 0.1 if _n <= 5
g estlb = estmean - invnormal(0.975)*estse
g estub = estmean + invnormal(0.975)*estse
g estlb_int = estmean_int - invnormal(0.975)*estse_int
g estub_int = estmean_int + invnormal(0.975)*estse_int

twoway (rcap estlb estub time1, lcolor(blue) mcolor(blue) horizontal) || ///
	   (scatter time1 estmean, lcolor(blue) mcolor(blue) msymbol(O)) || ///
	   (rcap estlb_int estub_int time2, lcolor(red) mcolor(red) horizontal) || ///
	   (scatter time2 estmean_int, lcolor(red) mcolor(red) msymbol(D)), ///
	   graphregion(color(white)) bgcolor(white) plotregion(fcolor(white)) xtitle("inflation expectation (in pp)") legend(label(2 "low") label(4 "high") order(2 4) rows(1) position(6)) xline(0, lcolor(black)) xscale(titlegap(2)) ytitle("") yscale(titlegap(2)) ylabel(1 "sectoral energy intensity" 2 "natural gas share" 3 "energy cost share" 4 "firm size" 5  "informedness about energy use", angle(0)) ylabel(, nogrid) xlabel(-0.2(0.2)0.5, nogrid) text(5 0.45 "p-value: ${p1}", size(small)) text(4 0.45 "p-value: ${p2}", size(small)) text(3 0.45 "p-value: ${p3}", size(small)) text(2 0.45 "p-value: ${p4}", size(small)) text(1 0.45 "p-value: ${p5}", size(small)) 
							 
graph display, xsize(20) ysize(10)

graph export "${path_export_graphs}\figure_6.pdf", replace 

drop estmean* estse* estlb* estub* time*

esttab using "${path_export_tables}\appendix_table_b12.tex", keep(tau*) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("firm FE & {yes} & {yes} & {yes} & {yes} & {yes}\\" "group x month FE  &  {yes} & {yes}  & {yes}& {yes}& {yes}\\" "\midrule" "$\text{H}_{0}$(coefficients equal): p-value & ${p1}${diff_stars1} & ${p2}${diff_stars2} & ${p3}${diff_stars3} & ${p4}${diff_stars4} & ${p5}${diff_stars5}\\ " "\midrule" "mean & ${mean1} &${mean2} & ${mean3}& ${mean4} & ${mean5} \\" "N & ${N1} &${N2} & ${N3} & ${N4} & ${N5} \\" "\# cluster & ${cluster1} &${cluster2} & ${cluster3} & ${cluster4}  & ${cluster5} \\"   "\bottomrule \bottomrule" ) nomtitles nonumbers fragment noobs  varlabel(tau_d_high_energy "treated x post price increase x high energy cost share" tau_d_low_energy "treated x post price increase x low energy cost share" tau_d_sector_intensive "treated x post price increase x energy-intensive sector" tau_d_sector_nonint "treated x post price increase x non-energy-intensive sector" tau_d_smallfirm  "treated x post price increase x small firm" tau_d_largefirm "treated x post price increase x large firm" tau_d_non_firm_gas "treated x post price increase x low natural gas share" tau_d_firm_gas "treated x post price increase x high natural gas share" tau_d_no_monitor_energy "treated x post price increase x not informed about energy use" tau_d_monitor_energy "treated x post price increase x informed about energy use") varwidth(50) substitute("\_" "_") replace

est clear 

*** Figure 7
mat estsave = J(4,2,.)
mat colname estsave = "estmean1" "estmean2"  
mat estse = J(4,2,.)
mat colname estse = "estse1" "estse2"  

qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, horizons(0(3)3) pretrends(3) autosample cluster(BBk_Sample_Key)  

*** Renormalize pre-trend to pre-treatment period
qui foreach f of numlist 1(1)2 {
	
	if `f' == 1 lincom - pre3
	else	    lincom - pre3 + pre3		
	
	mat estsave[`f',1] = `r(estimate)'
	mat estse[`f',1] = `r(se)'
		
}

*** Post-treatment effects
foreach t of numlist 1(1)2 {
	
	mat estsave[`=`t'+2',1] = e(b)[1,`t']
	mat estse[`=`t'+2',1] = `= sqrt(e(V)[`t',`t'])'
	
} // t

qui did_imputation price_current BBk_Sample_Key wave treatment_time, horizons(0(3)3) pretrends(3) autosample cluster(BBk_Sample_Key)  

*** Renormalize pre-trend to pre-treatment period
qui foreach f of numlist 1(1)2 {
	
	if `f' == 1 lincom - pre3
	else	    lincom - pre3 + pre3		
	
	mat estsave[`f',2] = `r(estimate)'
	mat estse[`f',2] = `r(se)'
		
}

*** Post-treatment effects
foreach t of numlist 1(1)2 {
	
	mat estsave[`=`t'+2',2] = e(b)[1,`t']
	mat estse[`=`t'+2',2] = `= sqrt(e(V)[`t',`t'])'
	
} // t

svmat estsave, names(col)
svmat estse, names(col)

*** Express time in terms of quarters
g time1 = _n - 3 - 0.05 if _n <= 4
g time2 = _n - 3 + 0.05 if _n <= 4 

forval t = 1/2 {
	
	g estlb`t' = estmean`t' - invnormal(0.975)*estse`t'
	g estub`t' = estmean`t' + invnormal(0.975)*estse`t'

} // t

twoway (rcap estlb1 estub1 time1 if time1 < -0.15, lcolor(blue) mcolor(blue)) || ///
	   (rcap estlb1 estub1 time1 if time1 >= -0.15, lcolor(blue) mcolor(blue)) || ///
	   (scatter estmean1 time1 if time1 < -0.15, mcolor(blue) msymbol(Oh)) || ///
	   (scatter estmean1 time1 if time1 >= -0.15, mcolor(blue) msymbol(O)) || ///
	   (rcap estlb2 estub2 time2 if time2 < -0.15, lcolor(red) mcolor(red)) || ///
	   (rcap estlb2 estub2 time2 if time2 >= -0.15, lcolor(red) mcolor(red)) || ///
	   (scatter estmean2 time2 if time2 < -0.15, mcolor(red) msymbol(Dh)) || ///
	   (scatter estmean2 time2 if time2 >= -0.15, mcolor(red) msymbol(D)), ///
	   graphregion(color(white)) bgcolor(white) plotregion(fcolor(white)) ytitle("percentage points") legend(label(3 "inflation expectation: placebo test") label(4 "inflation expectation: dynamic effects") label(7 "realized price change: placebo test") label(8 "realized price change: dynamic effects") order(3 4 7 8) rows(2) position(6)) yline(0, lcolor(black)) xlabel(-2(1)1) xscale(titlegap(2)) xtitle("quarters since price increase") yscale(titlegap(2)) nodraw xline(-0.5, lpattern(dash) lcolor(black)) 
			 
graph display, xsize(20) ysize(11)
 
graph export "${path_export_graphs}\figure_7.pdf", replace 

drop estmean* estse* estlb* estub* time*

*** Appendix Table B.9
eststo: qui did_imputation pricefuture BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key)  
add_info pricefuture, num(1) id(BBk_Sample_Key)
eststo: qui did_imputation pricefuture BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key sector_wave)  
add_info pricefuture, num(2) id(BBk_Sample_Key)
eststo: qui did_imputation pricefuture BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key sector_wave) timecontrols(energymix_*)  
add_info pricefuture, num(3) id(BBk_Sample_Key) 

esttab using "${path_export_tables}\appendix_table_b9.tex", keep(tau) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("firm FE & {yes} & {yes}& {yes} \\" "month FE & {yes} & & \\" "sector x month FE & & {yes} & {yes} \\" "energy share x month FE & & & {yes} \\" "\midrule" "mean & ${mean1} & ${mean2} & ${mean3} \\" "N & ${N1} & ${N2} & ${N3}\\" "\# cluster & ${cluster1} & ${cluster2} & ${cluster3}\\" "\bottomrule\bottomrule") nomtitles nonumbers fragment noobs varlabel(tau "treated x post price increase") varwidth(30) replace
		
est clear

*** Appendix Table B.10
eststo: qui did_imputation abs_predict_error BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) 
add_info abs_predict_error, num(1) id(BBk_Sample_Key)
eststo: qui did_imputation sq_predict_error BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) 
add_info sq_predict_error, num(2) id(BBk_Sample_Key)
eststo: qui did_imputation abs_difference_spf BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) 
add_info abs_difference_spf, num(3) id(BBk_Sample_Key)
eststo: qui did_imputation sq_difference_spf BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) 
add_info sq_difference_spf, num(4) id(BBk_Sample_Key)

esttab using "${path_export_tables}\appendix_table_b10.tex", keep(tau) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("firm FE  & {yes}& {yes}  & {yes}& {yes}\\" "month FE & {yes}&{yes} & {yes}& {yes} \\" "\midrule"  "mean & ${mean1} &${mean2}  & ${mean3} &${mean4} \\" "N & ${N1} &${N2} & ${N3} &${N4} \\" "\# cluster & ${cluster1} &${cluster2}& ${cluster3} &${cluster4} \\" "\bottomrule\bottomrule") nomtitles nonumbers fragment noobs varlabel(tau "treated x post price increase") varwidth(30) replace
		
est clear
 
*** Appendix Table B.11 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key)  
add_info inflexpoint, num(1) id(BBk_Sample_Key)
g in_sample = e(sample) == 1 // determine sample
eststo: qui reghdfe inflexpoint tau, absorb(BBk_Sample_Key wave) cluster(BBk_Sample_Key)  
add_info inflexpoint, num(2) id(BBk_Sample_Key)
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if in_sample == 1, cluster(BBk_Sample_Key) project(energypricechange)
add_info inflexpoint, num(3) id(BBk_Sample_Key)
eststo: qui reghdfe inflexpoint tau_energypricechange, absorb(BBk_Sample_Key wave) cluster(BBk_Sample_Key)  
add_info inflexpoint, num(4) id(BBk_Sample_Key)
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample wtr(d_low_increase d_high_increase) cluster(BBk_Sample_Key) 
pvalue, num(5)
add_info inflexpoint, num(5) id(BBk_Sample_Key)
drop in_sample

esttab using "${path_export_tables}\appendix_table_b11.tex", keep(tau tau_energypricechange tau_d_low_increase tau_d_high_increase) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("estimator & {BJS}& {TWFE}& {BJS}& {TWFE}& {BJS} \\" "firm FE & {yes} & {yes} & {yes} & {yes} & {yes}\\" "month FE & {yes} & {yes} &  {yes}& {yes} & {yes} \\" "\midrule"  "$\text{H}_{0}$(coefficients equal): p-value & & & & & ${p5}${diff_stars5}\\ " "\midrule" "mean & ${mean1} &${mean2} & ${mean3} & ${mean4} & ${mean5} \\" "N & ${N1} &${N2} & ${N3} & ${N4}& ${N5}\\"  "\# cluster & ${cluster1} &${cluster2} & ${cluster3} & ${cluster4}  & ${cluster5} \\" "\bottomrule \bottomrule") nomtitles nonumbers fragment noobs varlabel(tau "treated x post price increase" tau_energypricechange "treated x post price increase x 1\% price increase" tau_d_low_increase "treated x post below-median price increase" tau_d_high_increase "treated x post above-median price increase") varwidth(30) substitute("\_" "_") replace

est clear	

*** Appendix Table B.13
preserve 

use "${path_data}\bopf_early.dta", clear
 
local counter 0

foreach v of varlist percprob_e percprob_f percprob_g percprob_h {  
		
	local ++counter
	eststo: qui did_imputation `v' BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key)  
	add_info `v', num(`counter') id(BBk_Sample_Key) 
	
} // v

*** Appendix Table B.13: upper panel
esttab using "${path_export_tables}\appendix_table_b13_upper.tex", keep(tau) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("firm FE & {yes} & {yes} & {yes} & {yes} \\" "month FE  & {yes} & {yes} & {yes} & {yes} \\" "\midrule" "mean & ${mean1} &${mean2} & ${mean3} & ${mean4}  \\" "N & ${N1} &${N2} & ${N3}  & ${N4} \\" "\# cluster & ${cluster1} &${cluster2} & ${cluster3} & ${cluster4} \\" "\midrule") nomtitles nonumbers fragment noobs varwidth(40) varlabel(tau "treated x post price increase") replace

est clear

local counter 0

foreach v of varlist percprob_a percprob_b percprob_c percprob_d { 

	local ++counter
	eststo: qui did_imputation `v' BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key)  
	add_info `v', num(`counter') id(BBk_Sample_Key) 
	
} // v

*** Appendix Table B.13: lower panel
esttab using "${path_export_tables}\appendix_table_b13_lower.tex", keep(tau) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("firm FE & {yes} & {yes} & {yes} & {yes}  \\" "month FE & {yes} & {yes} & {yes} & {yes} \\" "\midrule" "mean & ${mean1} &${mean2} & ${mean3} & ${mean4} \\" "N & ${N1} &${N2} & ${N3}  & ${N4} \\" "\# cluster & ${cluster1} &${cluster2} & ${cluster3} & ${cluster4} \\"   "\bottomrule\bottomrule") nomtitles nonumbers fragment noobs varwidth(40) varlabel(tau "treated x post price increase") replace
	
est clear

restore 

*** Appendix Table B.14
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) 
add_info inflexpoint, num(1) id(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint_orig BBk_Sample_Key wave treatment_time [aw=wgt_outlier], autosample cluster(BBk_Sample_Key) 
add_info inflexpoint_orig, num(2) id(BBk_Sample_Key)
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key firmregion_wave) 
add_info inflexpoint, num(3) id(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) fe(BBk_Sample_Key empl_q_wave) 
add_info inflexpoint, num(4) id(BBk_Sample_Key) 

esttab using "${path_export_tables}\appendix_table_b14.tex", keep(tau) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("firm FE & {yes} & {yes}  & {yes} & {yes} \\" "month FE & {yes}& {yes} & {yes} & {yes}  \\"  "Huber robust estimation & & {yes} &  &  \\" "state x month FE &  & & {yes} & \\" "firm size x month FE &  & &  & {yes}\\" "\midrule" "mean & ${mean1} &${mean2} & ${mean3} & ${mean4}\\" "N & ${N1} &${N2} & ${N3} & ${N4}\\" "\# cluster & ${cluster1} &${cluster2} & ${cluster3} & ${cluster4} \\" "\bottomrule \bottomrule") nomtitles nonumbers fragment noobs varlabel(tau "treated x post price increase") varwidth(30) replace
	
est clear 

*** Appendix Table B.15
preserve 

use "${path_data}\bopf_wdec.dta", clear
	
qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key) delta(1)  
g in_sample = e(sample) == 1 // determine sample
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if in_sample == 1, cluster(BBk_Sample_Key) project(energypricechange) delta(1) 
add_info inflexpoint, num(1) id(BBk_Sample_Key)
eststo: qui xtscc inflexpoint tau i.wave if price_decrease != 1, fe  
add_info inflexpoint, num(2) id(BBk_Sample_Key)
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if interr == 0 & price_decrease != 1, autosample cluster(BBk_Sample_Key) delta(1) 
add_info inflexpoint, num(3) id(BBk_Sample_Key)
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if d_decisionmaker == 1 & price_decrease != 1, autosample cluster(BBk_Sample_Key) delta(1) 
add_info inflexpoint, num(4) id(BBk_Sample_Key)
drop in_sample

esttab using "${path_export_tables}\appendix_table_b15.tex", keep(tau tau_energypricechange) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("firm FE & {yes} & {yes} & {yes} & {yes} \\" "month FE & {yes} & {yes}& {yes} & {yes} \\" "keep price decreases &  {yes} & & & \\" "Driscoll-Kraay standard errors & & {yes}  &  & \\" "drop firms that interrupted the survey & & &  {yes} & \\" "keep only decision-makers & & & &  {yes} \\" "\midrule" "mean & ${mean1} &${mean2} & ${mean3} & ${mean4}\\" "N & ${N1} &${N2} & ${N3} & ${N4}\\" "\# cluster & ${cluster1} &${cluster2} & ${cluster3} & ${cluster4} \\" "\bottomrule \bottomrule") nomtitles nonumbers fragment noobs varlabel(tau "treated x post price increase" tau_energypricechange "treated x post price increase x 1\% price increase") varwidth(30) replace

est clear 

restore 

*** Appendix Table B.16 
qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time, autosample cluster(BBk_Sample_Key)  
g in_sample = e(sample) == 1 // determine sample
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if in_sample == 1, cluster(BBk_Sample_Key) project(energypricechange)
add_info inflexpoint, num(1) id(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if in_sample == 1, cluster(BBk_Sample_Key) project(energypricechange5)
add_info inflexpoint, num(2) id(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if in_sample == 1, cluster(BBk_Sample_Key) project(energypricechange10)
add_info inflexpoint, num(3) id(BBk_Sample_Key) 
drop in_sample 	
 
esttab using "${path_export_tables}\appendix_table_b16.tex", keep(tau_energypricechange*) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("firm FE & {yes} & {yes} & {yes}\\" "month FE & {yes} & {yes} & {yes}\\" "assumption about the open interval & {+ 0} & {+ 5} & {+ 10}\\" "\midrule" "mean & ${mean1} &${mean2} & ${mean3} \\" "N & ${N1} &${N2} & ${N3}\\"  "\# cluster & ${cluster1} &${cluster2} & ${cluster3} \\" "\bottomrule \bottomrule") nomtitles nonumbers fragment noobs varlabel(tau_energypricechange "treated x post price increase x 1\% price increase" tau_energypricechange5 "treated x post price increase x 1\% price increase" tau_energypricechange10 "treated x post price increase x 1\% price increase") varwidth(60) replace

est clear 

*** Appendix Table B.17 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if d_sources_one == 1, autosample cluster(BBk_Sample_Key) 
add_info inflexpoint, num(1) id(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if d_sources_two == 1, autosample cluster(BBk_Sample_Key) 
add_info inflexpoint, num(2) id(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if d_sources_three == 1, autosample cluster(BBk_Sample_Key) 
add_info inflexpoint, num(3) id(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if d_elec_50 == 1, autosample cluster(BBk_Sample_Key) 
add_info inflexpoint, num(4) id(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if d_elec_75 == 1, autosample cluster(BBk_Sample_Key) 
add_info inflexpoint, num(5) id(BBk_Sample_Key) 
eststo: qui did_imputation inflexpoint BBk_Sample_Key wave treatment_time if d_elec_90 == 1, autosample cluster(BBk_Sample_Key) 
add_info inflexpoint, num(6) id(BBk_Sample_Key)
 
esttab using "${path_export_tables}\appendix_table_b17.tex", keep(tau*) star(* 0.1 ** 0.05 *** 0.01) se(3) b(3) posthead("") postfoot("firm FE & {yes} & {yes} & {yes} & {yes} & {yes} & {yes}\\" "month FE & {yes} & {yes} & {yes}  & {yes}& {yes}& {yes}\\" "number of energy sources & 1 & 2 & {$\geq$ 3} & & & \\""electricity expenditure share &  & & & {$\geq$ 50\%} & {$\geq$ 75\%} & {$\geq$ 90\%}\\"  "\midrule" "mean & ${mean1} &${mean2} & ${mean3} & ${mean4} & ${mean5}& ${mean6} \\" "N & ${N1} &${N2} & ${N3} & ${N4} & ${N5}& ${N6}\\" "\# cluster & ${cluster1} &${cluster2} & ${cluster3} & ${cluster4}  & ${cluster5} & ${cluster6} \\" "\bottomrule \bottomrule") nomtitles nonumbers fragment noobs varlabel(tau "treated x post price increase") varwidth(50) replace

est clear
	 
*** Appendix Figure B.6
mat estsave = J(4,1,.)
mat colname estsave = "estmean1"  
mat estse = J(4,1,.)
mat colname estse = "estse1"  

qui did_imputation pricefuture BBk_Sample_Key wave treatment_time, horizons(0(3)3) pretrends(3) autosample cluster(BBk_Sample_Key)  

*** Renormalize pre-trend to pre-treatment period
qui foreach f of numlist 1(1)2 {
	
	if `f' == 1 lincom - pre3
	else	    lincom - pre3 + pre3		
	
	mat estsave[`f',1] = `r(estimate)'
	mat estse[`f',1] = `r(se)'
		
}

*** Post-treatment effects
foreach t of numlist 1(1)2 {
	
	mat estsave[`=`t'+2',1] = e(b)[1,`t']
	mat estse[`=`t'+2',1] = `= sqrt(e(V)[`t',`t'])'
	
} // t

svmat estsave, names(col)
svmat estse, names(col)

*** Express time in terms of quarters
g time1 = _n - 3 if _n <= 4 

g estlb1 = estmean1 - invnormal(0.975)*estse1
g estub1 = estmean1 + invnormal(0.975)*estse1

twoway (rcap estlb1 estub1 time1 if time1 < -0.15, lcolor(blue) mcolor(blue)) || ///
	   (rcap estlb1 estub1 time1 if time1 >= -0.15, lcolor(blue) mcolor(blue)) || ///
	   (scatter estmean1 time1 if time1 < -0.15, mcolor(blue) msymbol(Oh)) || ///
	   (scatter estmean1 time1 if time1 >= -0.15, mcolor(blue) msymbol(O)), ///
	   graphregion(color(white)) bgcolor(white) plotregion(fcolor(white)) ytitle("percentage points") legend(label(3 "price expectation: placebo test") label(4 "price expectation: dynamic effects") order(3 4) rows(1) position(6)) yline(0, lcolor(black)) xlabel(-2(1)1) xscale(titlegap(2)) xtitle("quarters since price increase") yscale(titlegap(2)) nodraw xline(-0.5, lpattern(dash) lcolor(black))  
							 
graph display, xsize(20) ysize(11)

graph export "${path_export_graphs}\appendix_figure_b6.pdf", replace 

drop estmean* estse* estlb* estub* time*
 	 
log close